package com.fzkjjt.account.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzkjjt.account.mapper.Account;
import com.fzkjjt.account.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: seata-simple
 * @description:
 * @author: FangZhen
 * @create: 2020-10-14 14:32
 **/
@Service
public class AccountService {

    @Autowired
    private AccountMapper accountMapper;

    public void debit(String userId, int money) {
        QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        Account account = accountMapper.selectOne(queryWrapper);
        account.setMoney(account.getMoney() - money);
        accountMapper.updateById(account);
    }
}
